package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ExtHelper;
import com.ruoyi.common.utils.uuid.IdGeneratorSnowflake;
import com.ruoyi.system.domain.PracticeCadetExperience;
import com.ruoyi.system.domain.PracticeCadetExperienceCount;
import com.ruoyi.system.mapper.PracticeCadetExperienceMapper;
import com.ruoyi.system.service.IPracticeCadetExperienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实践心得Service业务层处理
 *
 * @author dp
 * @date 2023-11-27
 */
@Service
public class PracticeCadetExperienceServiceImpl implements IPracticeCadetExperienceService {
    @Autowired
    private PracticeCadetExperienceMapper practiceCadetExperienceMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询实践心得
     *
     * @param experienceId 实践心得主键
     * @return 实践心得
     */
    @Override
    public PracticeCadetExperience selectPracticeCadetExperienceByExperienceId(Long experienceId) {
        return practiceCadetExperienceMapper.selectPracticeCadetExperienceByExperienceId(experienceId);
    }

    /**
     * 查询实践心得列表
     *
     * @param practiceCadetExperience 实践心得
     * @return 实践心得
     */
    @Override
    public List<PracticeCadetExperience> selectPracticeCadetExperienceList(PracticeCadetExperience practiceCadetExperience) {
        return practiceCadetExperienceMapper.selectPracticeCadetExperienceList(practiceCadetExperience);
    }


    /**
     * 查询实践心得合计列表
     *
     * @param submitBegin
     * @param submitEnd
     * @param baseId
     * @param experienceStatus
     * @return
     */
    @Override
    public List<PracticeCadetExperienceCount> selectPracticeCadetExperienceCount(String submitBegin, String submitEnd, String baseId, String experienceStatus) {
        return practiceCadetExperienceMapper.selectPracticeCadetExperienceCount(submitBegin, submitEnd, baseId, experienceStatus);
    }

    /**
     * 根据条件查询时间心得
     * @param submitBegin
     * @param submitEnd
     * @param baseId
     * @param cadetId
     * @param experienceStatus
     * @return
     */
    @Override
    public List<PracticeCadetExperience> getExperienceList(String submitBegin, String submitEnd, String baseId, String cadetId, String experienceStatus) {
        return practiceCadetExperienceMapper.getExperienceList(submitBegin, submitEnd, baseId, cadetId, experienceStatus);
    }

    /**
     * 新增实践心得
     *
     * @param practiceCadetExperience 实践心得
     * @return 结果
     */
    @Override
    public int insertPracticeCadetExperience(PracticeCadetExperience practiceCadetExperience) {
        practiceCadetExperience.setCreateTime(DateUtils.getNowDate());
        return practiceCadetExperienceMapper.insertPracticeCadetExperience(practiceCadetExperience);
    }

    /**
     * 修改实践心得
     *
     * @param practiceCadetExperience 实践心得
     * @return 结果
     */
    @Override
    public int updatePracticeCadetExperience(PracticeCadetExperience practiceCadetExperience) {
        return practiceCadetExperienceMapper.updatePracticeCadetExperience(practiceCadetExperience);
    }

    /**
     * 批量删除实践心得
     *
     * @param experienceIds 需要删除的实践心得主键
     * @return 结果
     */
    @Override
    public int deletePracticeCadetExperienceByExperienceIds(Long[] experienceIds) {
        return practiceCadetExperienceMapper.deletePracticeCadetExperienceByExperienceIds(experienceIds);
    }

    /**
     * 删除实践心得信息
     *
     * @param experienceId 实践心得主键
     * @return 结果
     */
    @Override
    public int deletePracticeCadetExperienceByExperienceId(Long experienceId) {
        return practiceCadetExperienceMapper.deletePracticeCadetExperienceByExperienceId(experienceId);
    }

    /**
     * 实体数据补全
     *
     * @param practiceCadetExperience 实体
     * @param userId                  用户id
     * @param crateType               创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(PracticeCadetExperience practiceCadetExperience, Long userId, Integer crateType) {
        //主键
        if (practiceCadetExperience.getExperienceId() == null || "".equals(practiceCadetExperience.getExperienceId())) {
            practiceCadetExperience.setExperienceId(ExtHelper.toString(idGeneratorSnowflake.nextId()));
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (practiceCadetExperience.getCreateBy() == null) {
                practiceCadetExperience.setCreateBy(userId.toString());
            }
            if (practiceCadetExperience.getCreateTime() == null) {
                practiceCadetExperience.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (practiceCadetExperience.getModifyBy() == null) {
            practiceCadetExperience.setModifyBy(userId);
        }
        //修改时间
        if (practiceCadetExperience.getModifyTime() == null) {
            practiceCadetExperience.setModifyTime(DateUtils.getNowDate());
        }
    }
}
